package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageList(DishPageQueryDTO dishPageQueryDTO) {
        PageResult pageResult = dishService.pageList(dishPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 根据id查询菜品
     * @return
     */
    @GetMapping("/{id}")
    public Result<DishVO> findById(@PathVariable Long id) {
        DishVO dishVO = dishService.findById(id);

        return Result.success(dishVO);
    }

    /**
     * 菜品起售、停售
     * @param dishDTO
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(DishDTO dishDTO, @PathVariable Integer status) {
        dishService.updateStatus(dishDTO, status);

        return Result.success();
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result<List<DishVO>> findByCategoryId(Long categoryId) {
        List<DishVO> dishes = dishService.findByCategoryId(categoryId);

        return Result.success(dishes);
    }

    /**
     * 新增菜品
     * @return
     */
    @PostMapping
    public Result<String> add(@RequestBody DishDTO dishDTO) {
        dishService.add(dishDTO);

        return Result.success();
    }

    /**
     * 修改菜品
     * @return
     */
    @PutMapping
    public Result<String> updateInfo(@RequestBody DishDTO dishDTO) {
        dishService.updateInfo(dishDTO);

        return Result.success();
    }

    /**
     * 批量删除菜品
     * @return
     */
    @DeleteMapping
    public Result<String> delete(Long[] ids) {
        dishService.delete(ids);

        return Result.success();
    }
}
